<?php
/**
 * @link https://www.leadshop.vip/
 * @copyright Copyright ©2020-2021 浙江禾成云计算有限公司
 */
namespace system\api;

use framework\common\BasicController;
use yii\web\ForbiddenHttpException;
use yii\web\ServerErrorHttpException;

/**
 * 后台用户管理器
 */
class RolesController extends BasicController
{
    public $modelClass = 'system\models\Roles';

    /**
     * 用于返回所有菜单信息
     * @return [type] [description]
     */
    public function actionList()
    {
        $modelClass = $this->modelClass;
        return $modelClass::find()->where(['is_deleted' => 0])->all();
    }

    /**
     * 处理数据分页问题
     * @return [type] [description]
     */
    public function actionDeleted()
    {
        $get        = Yii::$app->request->get();
        $modelClass = $this->modelClass;
        $id         = intval($get['id']);
        $model      = $modelClass::findOne($id);
        if ($model) {

                $model->deleted_time = time();
                $model->is_deleted   = 1;
                $data=['deleted_time'=>time(),'is_deleted'=>1];
                $result =  $modelClass::updateAll($data, ['id' => $id]);
                if ($result) {
                    // Yii::$app->getResponse()->setStatusCode(204);
                    return $result;
                } else {
                    throw new ForbiddenHttpException('删除失败，请检查is_deleted字段是否存在');
                }
        } else {
            throw new ForbiddenHttpException('删除失败，数据不存在');
        }
    }
}
